package com.shfl.servermanage.logic.model.bt.response;

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.github.pagehelper.util.StringUtil;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

import java.math.BigDecimal;
import java.util.List;

@ApiModel("取实时状态信息(CPU、内存、网络、负载)")
public class NetWorkResponse {

    @ApiModelProperty(value = "总接收 (字节数)", example = "446326699")
    private String downTotal;

    @ApiModelProperty(value = "总发送 (字节数)", example = "77630707")
    private String upTotal;

    @ApiModelProperty(value = "总收包 (个)", example = "1519428")
    private String downPackets;

    @ApiModelProperty(value = "总发包 (个)", example = "175326")
    private String upPackets;

    @ApiModelProperty(value = "下行流量 (KB)", example = "36.22")
    private String down;

    @ApiModelProperty(value = "上行流量 (KB)", example = "72.81")
    private String up;

    @ApiModelProperty(value = "CPU 实时信息", example = "[使用率,核心数]")
    private String cpu;

    @ApiModelProperty(value = "CPU使用率", example = "1.87")
    private BigDecimal cpuUsage;

    @ApiModelProperty(value = "cou核心数字", example = "1")
    private BigDecimal cpuCoreNumber;

    @ApiModelProperty(value = "内存实时信息", example = "")
    private String mem;

    @ApiModelProperty(value = "空闲内存", example = "1")
    private BigDecimal memFree;

    @ApiModelProperty(value = "总内存", example = "1")
    private BigDecimal memTotal;

    @ApiModelProperty(value = "缓存内存", example = "1")
    private BigDecimal memCached;

    @ApiModelProperty(value = "缓冲内存", example = "1")
    private BigDecimal memBuffers;

    @ApiModelProperty(value = "实际使用内存", example = "1")
    private BigDecimal memRealUsed;

    @ApiModelProperty(value = "负载实时信息", example = "")
    private String load;

    @ApiModelProperty(value = "15分钟平均负载", example = "1")
    private BigDecimal loadFifteen;

    @ApiModelProperty(value = "5分钟平均负载", example = "1")
    private BigDecimal loadFive;

    @ApiModelProperty(value = "1分钟平均负载", example = "1")
    private BigDecimal loadOne;


    public void getData() {
        List<String> cpuList = JSONUtil.toList(cpu, String.class);
        if (!CollectionUtil.isEmpty(cpuList) && cpuList.size() >= 2) {
            this.cpuUsage = new BigDecimal(cpuList.get(0));
            this.cpuCoreNumber = new BigDecimal(cpuList.get(1));
        }
        if (!StringUtil.isEmpty(mem)) {
            JSONObject memJson = (JSONObject) JSONUtil.parse(mem);
            if (memJson != null) {
                this.memFree = memJson.getBigDecimal("memFree");
                this.memTotal = memJson.getBigDecimal("memTotal");
                this.memCached = memJson.getBigDecimal("memCached");
                this.memBuffers = memJson.getBigDecimal("memBuffers");
                this.memRealUsed = memJson.getBigDecimal("memRealUsed");
            }
        }

        if (!StringUtil.isEmpty(load)) {
            JSONObject loadJson = (JSONObject) JSONUtil.parse(load);
            if (loadJson != null) {
                this.loadFifteen = loadJson.getBigDecimal("fifteen");
                this.loadFive = loadJson.getBigDecimal("five");
                this.loadOne = loadJson.getBigDecimal("one");
            }
        }
    }


    public String getDownTotal() {
        return downTotal;
    }

    public void setDownTotal(String downTotal) {
        this.downTotal = downTotal;
    }

    public String getUpTotal() {
        return upTotal;
    }

    public void setUpTotal(String upTotal) {
        this.upTotal = upTotal;
    }

    public String getDownPackets() {
        return downPackets;
    }

    public void setDownPackets(String downPackets) {
        this.downPackets = downPackets;
    }

    public String getUpPackets() {
        return upPackets;
    }

    public void setUpPackets(String upPackets) {
        this.upPackets = upPackets;
    }

    public String getDown() {
        return down;
    }

    public void setDown(String down) {
        this.down = down;
    }

    public String getUp() {
        return up;
    }

    public void setUp(String up) {
        this.up = up;
    }

    public String getCpu() {
        return cpu;
    }

    public void setCpu(String cpu) {
        this.cpu = cpu;
    }

    public String getMem() {
        return mem;
    }

    public void setMem(String mem) {
        this.mem = mem;
    }

    public String getLoad() {
        return load;
    }

    public void setLoad(String load) {
        this.load = load;
    }

    public BigDecimal getCpuUsage() {
        return cpuUsage;
    }

    public void setCpuUsage(BigDecimal cpuUsage) {
        this.cpuUsage = cpuUsage;
    }

    public BigDecimal getCpuCoreNumber() {
        return cpuCoreNumber;
    }

    public void setCpuCoreNumber(BigDecimal cpuCoreNumber) {
        this.cpuCoreNumber = cpuCoreNumber;
    }

    public BigDecimal getMemFree() {
        return memFree;
    }

    public void setMemFree(BigDecimal memFree) {
        this.memFree = memFree;
    }

    public BigDecimal getMemTotal() {
        return memTotal;
    }

    public void setMemTotal(BigDecimal memTotal) {
        this.memTotal = memTotal;
    }

    public BigDecimal getMemCached() {
        return memCached;
    }

    public void setMemCached(BigDecimal memCached) {
        this.memCached = memCached;
    }

    public BigDecimal getMemBuffers() {
        return memBuffers;
    }

    public void setMemBuffers(BigDecimal memBuffers) {
        this.memBuffers = memBuffers;
    }

    public BigDecimal getMemRealUsed() {
        return memRealUsed;
    }

    public void setMemRealUsed(BigDecimal memRealUsed) {
        this.memRealUsed = memRealUsed;
    }

    public BigDecimal getLoadFifteen() {
        return loadFifteen;
    }

    public void setLoadFifteen(BigDecimal loadFifteen) {
        this.loadFifteen = loadFifteen;
    }

    public BigDecimal getLoadFive() {
        return loadFive;
    }

    public void setLoadFive(BigDecimal loadFive) {
        this.loadFive = loadFive;
    }

    public BigDecimal getLoadOne() {
        return loadOne;
    }

    public void setLoadOne(BigDecimal loadOne) {
        this.loadOne = loadOne;
    }
}
